3 #include "ScreenNames.h"
4 #include "RescourceKeys.h"
5 using namespace std::chrono
;
10 Trainer::Trainer(int* scrn
, FileIO
* fileIO
, ResourceMaster
* resourcePointer
, int pattern
)
12 rsc
= resourcePointer
;
14 rio
= new RhythmIO(fileIO
);
15 tTools
= new TempoTools(rio
);
16 font
= new Fonts(0, rsc
);
17 renderer
= rsc
->rendPtr
;
19 outlineAnimation
= new Animation(rsc
->gameAnimations
.at(WhiteBlueBG
));
27 countDownDuration
= 300;
32 initializeBeats("Levels/T1");
36 initializeBeats("Levels/T2");
42 int col1
= font
->prcnt(0.1, 'x');
43 int col2
= font
->prcnt(0.2, 'x');
44 int col3
= font
->prcnt(0.3, 'x');
45 int col4
= font
->prcnt(0.5, 'x');
47 goalRect
= { col1
, font
->prcnt(0.1, 'y'), font
->prcnt(0.1, 'x') , font
->prcnt(0.1, 'y') };
48 subGoalRect
= { col2
, font
->prcnt(0.15, 'y'), font
->prcnt(0.05, 'x') , font
->prcnt(0.05, 'y') };
49 levelRect
= { col3
, font
->prcnt(0.2, 'y'), font
->prcnt(0.1, 'x') , font
->prcnt(0.1, 'y') };
51 nextRect
= { col4
, font
->prcnt(0.3, 'y'), font
->prcnt(0.1, 'x') , font
->prcnt(0.1, 'y') };
52 startRect
= { col4
, font
->prcnt(0.3, 'y'), font
->prcnt(0.1, 'x') , font
->prcnt(0.1, 'y') };
54 countDownRect
= { col2
, font
->prcnt(0.3, 'y'), font
->prcnt(0.1, 'x') , font
->prcnt(0.1, 'y') };
56 aheadRect
= { col3
, font
->prcnt(0.8, 'y'), font
->prcnt(0.1, 'x') , font
->prcnt(0.1, 'y') };
57 behindRect
= { col1
, font
->prcnt(0.8, 'y'), font
->prcnt(0.1, 'x') , font
->prcnt(0.1, 'y') };
58 perfectRect
= { col2
, font
->prcnt(0.8, 'y'), font
->prcnt(0.1, 'x') , font
->prcnt(0.1, 'y') };
60 light1Rect
= { col2
, font
->prcnt(0.7, 'y'), font
->prcnt(0.1, 'x') , font
->prcnt(0.1, 'y') };
61 light2Rect
= { col3
, font
->prcnt(0.7, 'y'), font
->prcnt(0.1, 'x') , font
->prcnt(0.1, 'y') };
62 light3Rect
= { col4
, font
->prcnt(0.7, 'y'), font
->prcnt(0.1, 'x') , font
->prcnt(0.1, 'y') };
63 light4Rect
= { col4
, font
->prcnt(0.7, 'y'), font
->prcnt(0.1, 'x') , font
->prcnt(0.1, 'y') };
66 mouseRect
= { col4
, font
->prcnt(0.1, 'y'), font
->prcnt(0.1, 'x') , font
->prcnt(0.1, 'y') };
67 mouseRightRect
= { col4
, font
->prcnt(0.5, 'y'), font
->prcnt(0.1, 'x') , font
->prcnt(0.1, 'y') };
68 mouseLeftRect
= { col4
, font
->prcnt(0.5, 'y'), font
->prcnt(0.1, 'x') , font
->prcnt(0.1, 'y') };
83 void Trainer::createText() {
85 font
->loadFont(SDL_Color
{ 0,0,0,0 }, rsc
->gameText
.at(GoalText
), 2);
86 goalText
= font
->getTexture();
87 font
->loadFont(SDL_Color
{ 0,0,0,0 }, rsc
->gameText
.at(SubGoalText
), 2);
88 subGoalText
= font
->getTexture();
89 font
->loadFont(SDL_Color
{ 0,0,0,0 }, rsc
->gameText
.at(Animation1Text
), 2);
90 levelText
= font
->getTexture();
92 font
->loadFont(SDL_Color
{ 0,0,0,0 }, rsc
->gameText
.at(NextText
), 2);
93 nextText
= font
->getTexture();
95 font
->loadFont(SDL_Color
{ 0,0,0,0 }, to_string(countDownTime
), 2);
96 countDownText
= font
->getTexture();
99 else if (isPattern1_2
) {
100 font
->loadFont(SDL_Color
{ 0,0,0,0 }, rsc
->gameText
.at(GoalText
), 2);
101 goalText
= font
->getTexture();
102 font
->loadFont(SDL_Color
{ 0,0,0,0 }, rsc
->gameText
.at(SubGoalText
), 2);
103 subGoalText
= font
->getTexture();
104 font
->loadFont(SDL_Color
{ 0,0,0,0 }, rsc
->gameText
.at(Animation1Text
), 2);
105 levelText
= font
->getTexture();
107 font
->loadFont(SDL_Color
{ 0,0,0,0 }, rsc
->gameText
.at(StartText
), 2);
108 startText
= font
->getTexture();
110 font
->loadFont(SDL_Color
{ 0,0,0,0 }, to_string(countDownTime
), 2);
111 countDownText
= font
->getTexture();
115 void Trainer::destroyText() {
116 SDL_DestroyTexture(goalText
);
117 SDL_DestroyTexture(subGoalText
);
118 SDL_DestroyTexture(levelText
);
119 SDL_DestroyTexture(startText
);
120 SDL_DestroyTexture(nextText
);
121 SDL_DestroyTexture(countDownText
);
124 void Trainer::loadPattern() {
126 initializeBeats("Levels/T1");
129 else if (isPattern1_2
) {
130 initializeBeats("Levels/T2");
135 void Trainer::update() {
137 if (isPattern1_2
&& x
> startRect
.x
&& x
< startRect
.x
+ startRect
.w
&& y
> startRect
.y
&& y
< startRect
.y
+ startRect
.h
) {
143 if (hoverStart
&& mouseClicked
&& !(playedOnce1
|| playedOnce2
)) {
146 if (start
&& isPattern1_2
) {
151 if (isPattern1_1
&& x
> nextRect
.x
&& x
< nextRect
.x
+ nextRect
.w
&& y
> nextRect
.y
&& y
< nextRect
.y
+ nextRect
.h
) {
157 if (hoverNext
&& mouseClicked
&& !(playedOnce1
|| playedOnce2
)) {
160 if (next
&& isPattern1_1
) {
161 isPattern1_1
= false;
169 tTools
->countDown(&countDownTime
, countDownDuration
);
170 if (countDownTime
< 0) {
173 tTools
->proccessDataSlow();
174 tTools
->moveTicker();
175 playCue
[0] = tTools
->autoPlay(10);
176 playCue
[1] = tTools
->autoPlay(20);
177 playCue
[1] = tTools
->autoPlay(30);
180 if (playCue
[0] == 1) {
182 light2Switch
= false;
188 light3Switch
= false;
196 if (leftMBSwitch
&& playCue
[0] == 1) {
197 leftMBSwitch
= false;
199 else if (playCue
[1] == 1) {
202 if (rightMBSwitch
&& playCue
[2] == 1) {
203 rightMBSwitch
= false;
205 else if (playCue
[2]== 1) {
206 rightMBSwitch
= true;
210 playSound1 = tTools->clickAccuracy(1);
211 std::cout << playSound1 << "\n";
212 if (playSound1 == 0) {
217 else if (playSound1 == 1) {
222 else if (playSound1 == -1) {
229 if (leftMouseClicked
&& !playedOnceL
) {
231 playSound
[0] = tTools
->clickAccuracy(1, true);
232 if (playSound
[0] == 0) {
233 light1Switch
= false;
234 light2Switch
= false;
241 if (playSound
[0] == 1) {
246 else if (playSound
[0] == -1) {
258 void Trainer::play() {
259 if (playCue
[0] == 1 ) {
260 rsc
->sptr
->playSFX(2);
263 if (playSound
[0] == 0 && !playedOnceL
) {
264 rsc
->sptr
->playSFX(3);
267 else if (playSound
[0] == 1 && !playedOnceL
) {
268 rsc
->sptr
->playSFX(1);
271 else if (playSound
[0] == -1 && !playedOnceL
) {
272 rsc
->sptr
->playSFX(1);
277 void Trainer::render() {
278 SDL_RenderClear(renderer
);
280 if (hoverStart
|| hoverNext
) {
281 SDL_RenderCopy(renderer
, outlineAnimation
->itterateAnimation(30), NULL
, &startRect
);
284 SDL_RenderCopy(renderer
, goalText
, NULL
, &goalRect
);
285 SDL_RenderCopy(renderer
, subGoalText
, NULL
, &subGoalRect
);
286 SDL_RenderCopy(renderer
, levelText
, NULL
, &levelRect
);
287 SDL_RenderCopy(renderer
, startText
, NULL
, &startRect
);
288 SDL_RenderCopy(renderer
, nextText
, NULL
, &nextRect
);
291 stream
<< fixed
<< setprecision(3) << countDownTime
;
292 string formattedCounter
= stream
.str();
294 font
->loadFont(SDL_Color
{ 0,0,0,0 }, formattedCounter
, 2);
295 countDownText
= font
->getTexture();
297 SDL_RenderCopy(renderer
, countDownText
, NULL
, &countDownRect
);
299 SDL_DestroyTexture(countDownText
);
302 SDL_RenderCopy(renderer
, rsc
->gameGraphics
.at(RedDark
), NULL
, &light1Rect
);
303 SDL_RenderCopy(renderer
, rsc
->gameGraphics
.at(RedDark
), NULL
, &light2Rect
);
304 SDL_RenderCopy(renderer
, rsc
->gameGraphics
.at(GreenDark
), NULL
, &light3Rect
);
307 SDL_RenderCopy(renderer
, rsc
->gameGraphics
.at(RedBright
), NULL
, &light1Rect
);
310 SDL_RenderCopy(renderer
, rsc
->gameGraphics
.at(RedBright
), NULL
, &light2Rect
);
313 SDL_RenderCopy(renderer
, rsc
->gameGraphics
.at(GreenBright
), NULL
, &light3Rect
);
317 SDL_RenderCopy(renderer
, rsc
->gameGraphics
.at(Mouse
), NULL
, &mouseRect
);
320 SDL_RenderCopy(renderer
, rsc
->gameGraphics
.at(MouseL
), NULL
, &mouseLeftRect
);
323 SDL_RenderCopy(renderer
, rsc
->gameGraphics
.at(MouseR
), NULL
, &mouseRightRect
);
328 SDL_RenderCopy(renderer
, rsc
->gameGraphics
.at(LArrow
), NULL
, &aheadRect
);
331 SDL_RenderCopy(renderer
, rsc
->gameGraphics
.at(RArrow
), NULL
, &behindRect
);
334 SDL_RenderCopy(renderer
, rsc
->gameGraphics
.at(Circle
), NULL
, &perfectRect
);
337 SDL_RenderPresent(renderer
);